require 'watir'
include Watir
require 'test/unit'
require 'test/unit/ui/console/testrunner'
require 'watir/testUnitAddons'
require 'watir/testcase'
require 'watir/contrib/enabled_popup'
class TC_Forums < Test::Unit::TestCase
  def test_01
    $ie.goto($UniVar)
    $ie.refresh()

    $ie.link(:text, 'Sign out').click
    $ie.link(:text, 'Join').click
    
    $ie.text_field(:index, 2).set('temp1')
    $ie.text_field(:index, 3).set('temp11')
    $ie.text_field(:index, 4).set('temp11')
    $ie.text_field(:index, 5).set('temp1@telligent.com')
    $ie.text_field(:index, 6).set('temp1@telligent.com')

    $ie.wait()
   $ie.button(:id, /ctl00_bcr_ctl01_ctl00_CreateAccount/).click
#    $ie.button(:id, /ctl00_bcr_ctl00___CreateAccount/).click
    $ie.link(:text, 'Forums').click
    $ie.link(:text, 'Home').click
    $ie.refresh()
    $ie.refresh()

    $ie.link(:text, 'Sign out').click
    $ie.link(:text, 'Join').click
    
    $ie.text_field(:index, 2).set('temp2')
    $ie.text_field(:index, 3).set('temp22')
    $ie.text_field(:index, 4).set('temp22')
    $ie.text_field(:index, 5).set('temp2@telligent.com')
    $ie.text_field(:index, 6).set('temp2@telligent.com')
    
   $ie.button(:id, /ctl00_bcr_ctl01_ctl00_CreateAccount/).click
#    $ie.button(:id, /ctl00_bcr_ctl00___CreateAccount/).click

    $ie.link(:text, 'Forums').click
    $ie.link(:text, 'temp1').click
    $ie.link(:text, 'Send temp1 a private message').click

    $ie.wait()
    ie2 = Watir::IE.attach(:title, 'Community Server - Private Message')
    ie2.text_field(:index, 3).value = "My Subject"

    temp_var = "temp word"
    ie2.ie.Document.parentWindow.execScript("tinyMCE.getInstanceById(tinyMCE.getEditorId('mce_editor_0')).execCommand('mceSetContent', false, '" + temp_var + "')")

#    ie2.button(:id, /ctl00_ctl01_bcr_PostForm___PostButton/).click
    $ie.button(:id, /ctl00_ctl00_bcr_bcr_PostForm_ctl04_PostButton/).click

    assert(ie2.contains_text('temp word'))
    assert(ie2.contains_text('My Subject'))
    assert(ie2.contains_text('temp2'))
    ie2.close()
    
    $ie.link(:text, 'Inbox').click
    assert($ie.contains_text('My Subject'))
    $ie.link(:text, 'Sign out').click
    $ie.link(:text, 'Sign in').click

    $ie.text_field(:id, /username/ ).set('temp1')
    $ie.text_field(:id, /password/ ).set('temp11')
    
    $ie.link(:id, /ctl00_bcr_ctl00_ctl03_loginButton/).click     
#    $ie.link(:id, /ctl00_bcr_Login1___loginButton/).click
    
    $ie.refresh()
    $ie.refresh()
    $ie.link(:text, 'Inbox').click
    assert($ie.contains_text('My Subject'))
    assert($ie.contains_text('temp2'))
    $ie.checkbox(:index, 1).set
    $ie.button(:value, 'Delete Checked').click
    
    $ie.link(:text, 'Sign out').click
    $ie.refresh()
    $ie.link(:text, 'Sign in').click
    
    $ie.text_field(:id, /username/ ).set($ADMIN)
    $ie.text_field(:id, /password/ ).set($PASSWORD)

    $ie.link(:id, /ctl00_bcr_ctl00_ctl03_loginButton/).click     
#    $ie.link(:id, /ctl00_bcr_Login1___loginButton/).click







    $ie.goto($UniVar + '/ControlPanel/Membership/membersearch.aspx?SelectedNavItem=BrowseMembers')

    $ie.div(:index, 141).click
    $ie.div(:index, 141).click
    $ie.link(:text, 'Actions').click
    $ie.cell(:id, /Menu_3$/).click
    $ie.frame(:index, 6).radio(:index, 2).set
    $ie.frame(:index, 6).button(:caption, 'Delete User').click

    $ie.refresh()
    $ie.refresh()
    $ie.refresh()
    $ie.refresh()
    $ie.refresh()
    $ie.refresh()
    $ie.goto($UniVar + '/ControlPanel/Membership/default.aspx')
    $ie.goto($UniVar + '/ControlPanel/Membership/membersearch.aspx?SelectedNavItem=BrowseMembers')
    $ie.refresh()
    $ie.refresh()
    $ie.refresh()
    $ie.refresh()
    $ie.refresh()
    $ie.refresh()


    $ie.div(:index, 141).click
    $ie.div(:index, 141).click
    $ie.link(:text, 'Actions').click
    $ie.cell(:id, /Menu_3$/).click
    $ie.frame(:index, 6).radio(:index, 2).set
    $ie.frame(:index, 6).button(:caption, 'Delete User').click
  end
end